package org.aeon.client.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.client.context.GlobalContext;
import org.aeon.entity.dto.FriendApplyDto;
import org.aeon.entity.dto.UserDto;
import org.aeon.message.response.FriendApplyListResponseMessage;

import java.util.LinkedHashMap;

import static org.aeon.client.context.MessageMap.MessageContextKey.FriendConfirmationList;

/**
 * @author: MissingAeon
 * @date: 2024/3/6 11:09
 * @description: 好友应用列表响应处理程序
 */
@Slf4j
@ChannelHandler.Sharable
public class FriendApplyListResponseHandler extends SimpleChannelInboundHandler<FriendApplyListResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FriendApplyListResponseMessage msg) throws Exception {
        if (msg.isSuccess()) {
            final LinkedHashMap<FriendApplyDto, UserDto> map = msg.getMap();
            log.debug("{}条好友请求信息", map.size());
            GlobalContext.getContext().getMessageMap().set(FriendConfirmationList, map);
        }
        ctx.fireChannelRead(msg);
    }
}
